package com.vhly.tuite.twclient.model;

import com.vhly.tuite.twclient.util.DOMUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Created by IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 2010-3-3
 * Time: 17:40:22
 */
public class Status implements Model {
    public String created_at;
    public String id;
    public String text;
    public String source;
    public boolean truncated;
    public String reply_to_status_id;
    public String reply_to_user_id;
    public boolean favorited;
    public String reply_to_screen_name;
    public User user;

    public void parse(Element el) {
        NodeList nl = el.getElementsByTagName("created_at");
        Element edl;
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            created_at = DOMUtil.getTextFromElement(edl);
        }
        nl = el.getElementsByTagName("id");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            id = DOMUtil.getTextFromElement(edl);
        }
        nl = el.getElementsByTagName("text");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            text = DOMUtil.getTextFromElement(edl);
        }
        nl = el.getElementsByTagName("source");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            source = DOMUtil.getTextFromElement(edl);
        }

        nl = el.getElementsByTagName("truncated");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            String str = DOMUtil.getTextFromElement(edl);
            truncated = str != null && str.equals("true");
        }

        nl = el.getElementsByTagName("reply_to_status_id");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            reply_to_status_id = DOMUtil.getTextFromElement(edl);
        }

        nl = el.getElementsByTagName("reply_to_user_id");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            reply_to_user_id = DOMUtil.getTextFromElement(edl);
        }

        nl = el.getElementsByTagName("favorited");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            String str = DOMUtil.getTextFromElement(edl);
            favorited = str != null && str.equals("true");
        }

        nl = el.getElementsByTagName("reply_to_screen_name");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            reply_to_screen_name = DOMUtil.getTextFromElement(edl);
        }

        nl = el.getElementsByTagName("user");
        if (nl != null && nl.getLength() > 0) {
            edl = (Element) nl.item(0);
            user = new User();
            user.parse(edl);
        }

    }
}
